import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 审计实体操作类型 */
export enum OperateTypeEnum {
  /** 查询 */
  Query = 1,
  /** 新增 */
  Insert = 2,
  /** 更新 */
  Update = 3,
  /** 删除 */
  Delete = 4,
}

/** 审计实体操作类型实体 */
export class OperateTypeEntity {
  /** 审计实体操作类型 */
  OperateType: OperateTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(operateType: OperateTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.OperateType = operateType;
    this.Color = color;
    switch (operateType) {
      case OperateTypeEnum.Query:
        // this.Display = '查询';
        this.Display = t('enum.operateType.query');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case OperateTypeEnum.Insert:
        // this.Display = '新增';
        this.Display = t('enum.operateType.insert');
        this.Color = this.Color ? this.Color : PresetColorEnum.Lime;
        break;
      case OperateTypeEnum.Update:
        // this.Display = '更新';
        this.Display = t('enum.operateType.update');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case OperateTypeEnum.Delete:
        // this.Display = '删除';
        this.Display = t('enum.operateType.delete');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取审计实体操作类型枚举架构
/**
 * 获取审计实体操作类型枚举架构
 */
export function getOperateTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: OperateTypeEntity[] = [
    new OperateTypeEntity(OperateTypeEnum.Query),
    new OperateTypeEntity(OperateTypeEnum.Insert),
    new OperateTypeEntity(OperateTypeEnum.Update),
    new OperateTypeEntity(OperateTypeEnum.Delete),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.OperateType as number,
      label: item.Display,
      value: item.OperateType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
